package com.ws.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ws.entity.Goods;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface GoodsMapper extends BaseMapper<Goods> {


    @Select("<script>" +
            "select  " +
            "g.id, " +
            "g.`name`, " +
            "g.goods_type_id, " +
            "t.`name` goods_Type_name, " +
            "g.price, " +
            "g.discount, " +
            "g.description, " +
            "g.remark, " +
            "g.count, " +
            "g.logo, " +
            "g.pics, " +
            "g.is_on_sale, " +
            "g.insert_time, " +
            "g.sale_count " +
            "from shop_goods g left join shop_goods_type t " +
            "on g.goods_type_id = t.id " +
            "where 1 = 1 " +
            "<if test='name != \"\"'>" +
            "and g.`name` like '%${name}%' " +
            "</if>" +
            "<if test=' goodsTypeId != null'>" +
            "and g.goods_type_id = '${goodsTypeId}' " +
            "</if>" +
            "<if test= 'isOnSale != null'>" +
            "and g.is_on_sale = '${isOnSale}' " +
            "</if>" +
            "</script>")
    Page<Goods> getGoodsListForPage(
            Page<Goods> p,
            @Param("name") String name,
            @Param("goodsTypeId") Long goodsTypeId,
            @Param("isOnSale") Integer isOnSale);
    
    @Select("select   " +
            "id,  " +
            "`name`,   " +
            "goods_type_id,  " +
            "price,  " +
            "discount,  " +
            "description,  " +
            "remark,  " +
            "count  " +
            "logo,  " +
            "pics,  " +
            "is_on_sale,  " +
            "insert_time,  " +
            "sale_count   " +
            "from shop_goods   " +
            "order by sale_count desc  " +
            "limit 0,5")
    List<Goods> getHotGoods();
}
    

